package com.ykq.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ykq.system.entity.Role;
import com.ykq.system.mapper.RoleMapper;
import com.ykq.system.service.IRoleService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ykq.system.vo.CommonResult;
import com.ykq.system.vo.RoleVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 闫克起
 * @since 2022-08-08
 */
@Service
public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements IRoleService {
    @Autowired
    private RoleMapper roleMapper;
    @Override
    public CommonResult selectRole(Integer currentPage, Integer pageSize, RoleVo roleVo) {
        Page<Role> page = new Page<>(currentPage,pageSize);

        QueryWrapper<Role> wrapper=new QueryWrapper<>();
        if(StringUtils.hasText(roleVo.getRoleName())){
                wrapper.like("role_name",roleVo.getRoleName());
        }
        if(StringUtils.hasText(roleVo.getBeginDate())){
              wrapper.ge("gmt_create",roleVo.getBeginDate());
        }
        if(StringUtils.hasText(roleVo.getEndDate())){
            wrapper.le("gmt_create",roleVo.getEndDate());
        }
        roleMapper.selectPage(page,wrapper);

        return new CommonResult(2000,"查询成功",page);
    }
}
